package com.easyidea.its.domain.service.department.impl;

import java.util.Collection;
import java.util.List;

import org.hibernate.Query;

import com.easyidea.its.domain.model.system.Department;
import com.easyidea.its.domain.repository.department.DepartmentRepository;
import com.easyidea.its.domain.service.base.impl.BaseServiceImpl;

public class DepartmentServiceImpl extends BaseServiceImpl<Department> implements
		com.easyidea.its.domain.service.department.DepartmentService {

	private DepartmentRepository departmentRepository;
	
	@Override
	public DepartmentRepository getBaseRepository() {
		return departmentRepository;
	}	
	public void setDepartmentRepository(DepartmentRepository departmentRepository) {
		this.departmentRepository = departmentRepository;
	}

	public int getDeparmentsCount(Department dept) {
		// TODO Auto-generated method stub
		return departmentRepository.getDeparmentsCount(dept);
	}

	public List<Department> getDepartments(Department dept, int startAtIndex,
			int pageSize) {
		// TODO Auto-generated method stub
		return departmentRepository.getDepartments(dept, startAtIndex, pageSize);
	} 
	public Collection<Department> getAllDepartments() {
		return departmentRepository.executeHqlCol(" from " + Department.class.getName());
	}

	public boolean hasSameDeptName(String deptName, Integer id) {
		// TODO Auto-generated method stub
		return departmentRepository.hasSameDeptName(deptName, id);
	}

   public  void removeDepartment(Integer id) {
		Query q = this.getSessionFactory().getCurrentSession().createQuery(
				"delete from " + Department.class.getName() + " where id = "
						+ id);
		q.executeUpdate();	   
   }
}
